//
//  CustomUploadPhotoAlert.m
//  ExcellentHome
//
//  Created by Andy on 15/11/12.
//  Copyright © 2015年 陈区. All rights reserved.
//

#import "CustomUploadPhotoAlert.h"
#import "SEGAlertView.h"

@interface CustomUploadPhotoAlert ()

@end

@implementation CustomUploadPhotoAlert

- (void)loadView
{
    UIScreen* scr = [UIScreen mainScreen];

    CGRect appbounds = CGRectMake(0, 0, scr.bounds.size.width, scr.bounds.size.height);

    UIView* mainView = [[UIView alloc] initWithFrame:appbounds];

    self.view = mainView;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:YES];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
        [SEGAlertView showTmepMessageWithMessage:@"iOS8以上系统才支持发布图片"];
        return;
    }
    [UIView animateWithDuration:0.5 animations:^{
        planeView.transform = CGAffineTransformMakeTranslation(0, 0);
    }];

    //弹出背景
    NSArray* titleArray = @[ @"从手机选择", @"相机", @"取消" ];

    UIAlertController* alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

    [self presentViewController:alertVC animated:YES completion:nil];

    [alertVC addAction:[UIAlertAction actionWithTitle:[titleArray objectAtIndex:0] style:UIAlertActionStyleDefault handler:^(UIAlertAction* _Nonnull action) {
                 [UIView animateWithDuration:0.2 animations:^{
                     planeView.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(planeView.bounds));
                 }
                     completion:^(BOOL finished){

                     }];
                 [self.fundelegate UploadPhotoAction:0 alertView:self];
             }]];
    [alertVC addAction:[UIAlertAction actionWithTitle:[titleArray objectAtIndex:1] style:UIAlertActionStyleDefault handler:^(UIAlertAction* _Nonnull action) {

                 [UIView animateWithDuration:0.2 animations:^{
                     planeView.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(planeView.bounds));
                 }
                     completion:^(BOOL finished){

                     }];
                 [self.fundelegate UploadPhotoAction:1 alertView:self];

             }]];
    [alertVC addAction:[UIAlertAction actionWithTitle:[titleArray objectAtIndex:2] style:UIAlertActionStyleCancel handler:^(UIAlertAction* _Nonnull action) {

                 [UIView animateWithDuration:0.2 animations:^{
                     planeView.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(planeView.bounds));
                 }
                     completion:^(BOOL finished){

                     }];
                 [self.fundelegate UploadPhotoAction:2 alertView:self];

             }]];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIView* bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
    bgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [self.view addSubview:bgView];

    planeView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.bounds) - 150, CGRectGetWidth(self.view.bounds), 160)];
    planeView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:planeView];
    planeView.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(planeView.bounds));

}

- (void)btnAction:(UIButton*)sender
{
    [UIView animateWithDuration:0.2 animations:^{
        planeView.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(planeView.bounds));
    }
        completion:^(BOOL finished){

        }];
    [self.fundelegate UploadPhotoAction:(int)sender.tag alertView:self];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
